package com.example.util;

import java.util.HashMap;
import java.util.Map;

public class MapUtil {

    /**
     * 将Map<String, Object>转换为Map<String, String>
     * 使用toString()方法进行转换
     */
    public static Map<String, String> objectMapToStringMap(Map<String, Object> objectMap) {
        if (objectMap == null) {
            return new HashMap<>();
        }

        Map<String, String> stringMap = new HashMap<>();
        for (Map.Entry<String, Object> entry : objectMap.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();

            if (value == null) {
                stringMap.put(key, null);
            } else {
                stringMap.put(key, value.toString());
            }
        }
        return stringMap;
    }
}
